home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 7
/
Apprentice-Release7.iso
/
Environments
/
Clean 1.2.4
/
IO Examples
/
Simple DataBase
/
listextensions.icl
< prev
Wrap
Text File
|
1997-04-24
|
1KB
|
41 lines
implementation module listextensions
import StdInt, StdBool, StdString, StdList, StdMisc
insertAt :: !Int .a u:[.a] -> v:[.a], [u <= v]
insertAt i x ys = before ++ [ x : at ] where (before,at) = splitAt i ys
updateAt :: !Int .a [.a] -> [.a]
updateAt i x ys = before ++ [ x : case at of [] -> []; [r:rs] -> rs ] where (before,at) = splitAt i ys
insertindex :: !(a -> a -> Bool) !a !u:[a] -> (!Int,!v:[a]), [u <= v]
insertindex r x ls = inserti r 0 x ls
where
inserti :: !(a -> .(a -> .Bool)) !Int !a !u:[a] -> (!Int,!v:[a]), [u <= v]
inserti r i x ls=:[y:ys]
| r x y = ( i,[x:ls])
| otherwise = (index,[y:list]) with (index,list) = inserti r (inc i) x ys
inserti _ i x _ = ( i,[x])
removeindex :: !a !u:[a] -> (!Int,!v:[a]) | ==, toString a, [u <= v]
removeindex e xs = removei e xs 0
where
removei :: !a !u:[a] !Int -> (!Int,v:[a]) | ==, toString a, [u <= v]
removei e [x:xs] i
| x==e = (i,xs)
| otherwise = (j,[x:res]) with (j,res) = removei e xs (inc i)
removei e _ _ = abort ("Err: "+++toString e+++" not removable!")
moveinlist :: !Int !Int !.[a] -> [a]
moveinlist src dest l // should be in StdList
| src < dest = remove src beforedest ++ [l!!src : atdest]
| src > dest = beforedest ++ [l!!src : remove (src - dest) atdest]
| otherwise = l
where
(beforedest,atdest) = splitAt dest l
splitby :: a !.[a] -> [.[a]] | == a
splitby x ys = case rest of [] -> [firstpart]; [r:rs] -> [firstpart:splitby x rs]
where
(firstpart,rest) = span ((<>) x) ys